<?php
namespace S\Validate\Type;

class File extends \S\Validate\Abstraction {
	protected $_default_settings = array(
		'min'   => 5,
		'max'   => 1024*10,
	);

	protected function action($value, $filter=\S\Validate\Handler::VALIDATOR, array $option=array()) {
        $info = getimagesize($value['tmp_name']);
        $type = $info['mime'];
		$error = array('error_message'=>'图片格式错误', 'error'=> $option['error']);
		if (!($type === 'image/jpeg' ||  $type === 'image/png')) {
			$error['Type']  = 'error.file_type';
			return $this->exception_check_params_handle($filter, $error);
		}
		return $value;
	}
}
